import i2c

class i2c_dev:
  ref=None
  def __init__(self,dev_path):
    self.ref=i2c.open("/dev/i2c-5")
  
  def slave(self,slave):
    i2c.slave(self.ref,slave)
  
  def read(self,adr=None):
    if adr!=None:
      return i2c.read(self.ref,adr)
    else:
      return i2c.read(self.ref)
      
  def write(self,value,adr=None):
    if adr!=None:
      return i2c.write(self.ref,value,adr)
    else:
      return i2c.write(self.ref,value)

  def __del__(self):
    if i2c:
      i2c.close(self.ref)
